package com.jymj.entity.gantt;

import com.jymj.utils.DateUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/7/13.
 */
public class PjTaskEntity implements Serializable {

    private Integer id;
    private Integer pjid;
    private Integer taskid;
    private Integer fatherid;
    private String title;
    private String title1;
    private Date t_start;
    private Date t_end;
    private Integer days_planned = 0;
    private Double progress = 0d;
    private Boolean unscheduled;
    private String res;
    private Integer res_id;
    private double cost = 0;
    private transient double guarantee;
    private String desc;
    private transient String remark;
    private Integer orderid;
    private Integer isaggregate;
    private String popmsg;
    private String code;
    private List<GanttLinkEntity> links;
    /**
     * 正常 0（黄） 滞后 1（红） 超前 2（绿）
     */
    private Integer waring = 0;
    private List<PjTaskEntity> children = new ArrayList<>();
    private List<PjtaskFile> pjtaskFileList = new ArrayList<>();
    /**
     * project 0 task 1 mil 2
     */
    private Integer type;//不能等于0，会忽略数据库原始NULL
    /**
     * 2017-11-19 计算后续任务，开始结束时间无效；最初数据都以工期+前置任务推算；当开始时间填写数据，则参与推算 0 开始无效，不参与计算 1 开始有效
     */
    private Integer status;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPjid() {
        return pjid;
    }

    public void setPjid(Integer pjid) {
        this.pjid = pjid;
    }

    public Integer getTaskid() {
        return taskid;
    }

    public void setTaskid(Integer taskid) {
        this.taskid = taskid;
    }

    public Integer getFatherid() {
        return fatherid;
    }

    public void setFatherid(Integer fatherid) {
        this.fatherid = fatherid;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getT_start() {
        return t_start;
    }

    public void setT_start(Date t_start) {
        this.t_start = t_start;
    }

    public Date getT_end() {
        return t_end;
    }

    public void resetTask() {
        if (days_planned != null && days_planned >= 0) {
            this.setT_end(DateUtils.AddDay(this.getT_start(), days_planned));
        } else if (days_planned < 0) {
            days_planned = 0;
            this.setT_end(DateUtils.AddDay(this.getT_start(), days_planned));
        } else {
            this.setDays_planned(DateUtils.BetweenDays(this.getT_end(), this.getT_start()));
        }
    }

    public void setT_end(Date t_end) {
        this.t_end = t_end;
    }

    public Integer getDays_planned() {
        if (type == null || type == 0 || t_end == null || t_start == null) {
            return 0;
        } else if (t_end.compareTo(t_start) >= 0) {
            return DateUtils.BetweenDays(t_end, t_start);
        } else {
            return 0;
        }
    }

    public void setDays_planned(Integer days_planned) {
        this.days_planned = days_planned;
    }

    public Double getProgress() {
        return progress;
    }

    public void setProgress(Double progress) {
        this.progress = progress;
    }

    public Integer getResId() {
        return res_id;
    }

    public void setResId(Integer resId) {
        this.res_id = resId;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public double getGuarantee() {
        return guarantee;
    }

    public void setGuarantee(double guarantee) {
        this.guarantee = guarantee;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getOrderid() {
        return orderid;
    }

    public void setOrderid(Integer orderid) {
        this.orderid = orderid;
    }

    public String getRes() {
        return res;
    }

    public void setRes(String res) {
        this.res = res;
    }

    public Integer getIsaggregate() {
        return isaggregate;
    }

    public void setIsaggregate(Integer isaggregate) {
        this.isaggregate = isaggregate;
    }

    public String getPopmsg() {
        return popmsg;
    }

    public void setPopmsg(String popmsg) {
        this.popmsg = popmsg;
    }

    public List<PjtaskFile> getPjtaskFileList() {
        return pjtaskFileList;
    }

    public void setPjtaskFileList(List<PjtaskFile> pjtaskFileList) {
        this.pjtaskFileList = pjtaskFileList;
    }

    public List<PjTaskEntity> getChildren() {
        return children;
    }

    public void setChildren(List<PjTaskEntity> children) {
        this.children = children;
    }

    public Integer getWaring() {
        return waring;
    }

    public void setWaring(Integer waring) {
        this.waring = waring;
    }

    public String getString() {
        String task = "";
        if (id != null) {
            task += "id:" + id.toString();
        }
        if (pjid != null) {
            task += " pjid:" + pjid.toString();
        }
        if (taskid != null) {
            task += " taskid:" + taskid.toString();
        }
        if (fatherid != null) {
            task += " fatherid:" + fatherid.toString();
        }
        if (title != null) {
            task += " title:" + title;
        }
        if (progress != null) {
            task += " progress" + progress.toString();
        }
        if (t_start != null) {
            task += " start" + t_start.toString();
        }
        if (t_end != null) {
            task += " end" + t_end.toString();
        }
        return task;
    }

    public String getTitle1() {
        return title1;
    }

    public void setTitle1(String title1) {
        this.title1 = title1;
    }

    public Boolean isUnscheduled() {
        return unscheduled;
    }

    public void setUnscheduled(Boolean unscheduled) {
        this.unscheduled = unscheduled;
    }

    public List<GanttLinkEntity> getLinks() {
        return links;
    }

    public void setLinks(List<GanttLinkEntity> links) {
        this.links = links;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getStatus() {
        if (status == null) {
            return 0;
        }
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}
